var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
var showbg = true;
var serverpath = "/";
var ajaxtimeout = 100000;
function loading(show)
{
	if (show)
	{}
	else
	{}
}
function hideFloat(floatdiv)
{
	$("#"+floatdiv).remove();
	$("#BoxBg").remove();
}
function showFloatBg(floatdiv)
{
	$("#"+floatdiv).before(bgfloat);
	$("#BoxBg").addClass("floatBg");
	$("#BoxBg").show();	
	$("#BoxBg").css({opacity:"0.2"});
}
function addDiv(divid,css,before)
{
	if(before == undefined || before == "")
		before = "body";
	$(before).append("<div id='"+divid+"' class='"+css+"' ></div>");
	
}
function closeFloat(div,fun)
{
	$("[@id*=close]").click(function()
	{	
		if(div =='avatardiv') 
		{
			$("#byear").show();
			$("#bmonth").show();
			$("#bday").show();				
		}
		hideFloat(div)
		try
		{
			//alert('close try');
			loading();
			hideMedia('show');	
		}
		catch(err)
		{}
		if(fun != '' && fun != undefined)
		{   
			eval(fun);
		}
		return false;
	})
	movePopBox();
}
function movePopBox()
{
	var startdrag = false;
	var mx = 0;
	var my = 0;
	var moffsetTop = 0;
	var moffsetLeft = 0;

	var screenwidth = $(document).width() - $("#popiframe").width()-10;
	var screenheight = $(document).height() - $("#popiframe").height()-10;
	$(".menubar").mousedown(function(e)
	{
		startdrag = true;
		if(is_ie)
		{	
			mx = event.x; 
			my = event.y;
		 }
		 else
		 {
		    mx = e.pageX ; 
			my = e.pageY;
		 }
		 moffsetTop = $("#popiframe").offset().top; 
		 moffsetLeft = $("#popiframe").offset().left; 

		 
	})
	$(document).mousemove(function(e)
	{ 
		if(startdrag == true) 
		{
			
			if(is_ie)
				{ 
					
					if(moffsetTop+event.y-my>0 && moffsetLeft+event.x-mx>0 && moffsetLeft+event.x-mx < screenwidth && moffsetTop+event.y-my<screenheight)
					{
						$("#popiframe").css('left',moffsetLeft+event.x-mx+'px');
						$("#popiframe").css('top', moffsetTop+event.y-my+'px'); 
					}
				}
				else
				{
					
					if(moffsetTop+e.pageY-my>0 && moffsetLeft+e.pageX-mx>0 && moffsetLeft+e.pageX-mx < screenwidth && moffsetTop+e.pageY-my<screenheight)
					{
						$("#popiframe").css('left',moffsetLeft+e.pageX-mx+'px'); 
						$("#popiframe").css('top', moffsetTop+e.pageY-my+'px');
					}
				}
			
		}
	});
	$(document).mouseup(function()
	{ 
		
		startdrag = false; 
	});
		    
}
function resizebox(width,height)
{
	var bodyheight = height-25;

	$("#iframebox").css("height",bodyheight+'px');
	$("#popiframe").css({ height: height+"px", width: width+"px" });
	
}

function showDiv(id,width,height,title,fun,parmas)
{
	
	var popdiv = "popiframe";
	var div = "popdiv";
 	$.ajax  
	({
		type: "get",
		url: serverpath+"html",
		data: "act="+id+(parmas==null?"":parmas),
		timeout: ajaxtimeout,
		beforeSend:function()
		{
			loading(true);
		},
		success:function(text)
		{
			loading(false);
			addDiv(div);
		 	document.getElementById(div).innerHTML=popiframe; 
			$("#iframebox").html(text);
			$("#"+popdiv).before(bgfloat);
			$("#"+popdiv).css({top:($(document).scrollTop()+120)+"px"});
			$("#BoxBg").addClass("floatBg");	
			$("#BoxBg").show();
			$("#BoxBg").css({opacity:"0.5"});
			$("#"+popdiv).css({left:(($(document).width()/2)-(width/2))+"px"});
			resizebox(width,height);
			$("#popboxtitle").html(title);
			closeFloat(div);
			if(fun != null)
				eval(fun)
			
		},
		error:function()
		{},
		complate:function()
		{}
	})
}


var popiframe = "<div id='popiframe' class='popbox'><div class = 'menubar'>";
	popiframe +="<em><span id=\"closewin\"><a href=\"#\" class=\"closewinbutton\" title=\"关闭\" id=\"closewinbutton\">关闭</a></span></em>";
	popiframe +="<span id =\"popboxtitle\" >个人资料</span></div>";
	popiframe +="<div id='iframebox' class='iframebox'>";
	popiframe +="</div></div>";

var bgfloat= "";
var iframes = new Array();
var iframestitle = new Array();

$(document).ready(function(){ 
	
	bgfloat="<div id=\"BoxBg\" style=\"height:"+$(document).height()+"px;filter:alpha(opacity=0);opacity:0;\"></div>";	
})
